package com.jrx.anytxn.param.job.bactchlimitadjust.step;

import com.jrx.anytxn.param.job.bactchlimitadjust.bean.LimitAdjustBean;
import com.jrx.anytxn.param.mapper.ext.ExtBtLimitAdjustInfoMapper;
import com.jrx.anytxn.param.mapper.ext.ExtTlBatchAdjustLimitMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 批量调额writer
 *
 * @author : zhenghaopu
 * 2020/1/6
 */
@Service
public class BatchLimitAdjustStep1Writer implements ItemWriter<LimitAdjustBean> {

    @Resource
    private ExtBtLimitAdjustInfoMapper extBtLimitAdjustInfoMapper;

    @Resource
    private ExtTlBatchAdjustLimitMapper extTlBatchAdjustLimitMapper;

    @Override
    public void write(List<? extends LimitAdjustBean> items) throws Exception {
        if(CollectionUtils.isNotEmpty(items)){
            for(LimitAdjustBean bean : items){
                extBtLimitAdjustInfoMapper.batchInsert(bean.getBtLimitAdjustInfoList());
                extTlBatchAdjustLimitMapper.batchUpdate(bean.getTlBatchAdjustLimitList());
            }
        }




    }
}
